package com.hivekion.system.controller;

import com.hivekion.common.annotation.AutoLog;
import com.hivekion.common.entity.TreeNode;
import com.hivekion.common.enums.OperationTypeEnum;
import com.hivekion.system.domain.vo.dict.SysDictTypeCreateVo;
import com.hivekion.system.domain.vo.dict.SysDictTypeModelVo;
import com.hivekion.system.domain.vo.dict.SysDictTypeUpdateVo;
import com.hivekion.system.domain.vo.dict.SysDictTypeViewVo;
import com.hivekion.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/dictType")
public class SysDictTypeController {

    @Autowired
    ISysDictTypeService dictTypeService;

    @PostMapping("/checkTypeNameUnique")
    public boolean checkTypeNameUnique(String typeName, String key) {
        return dictTypeService.checkTypeNameUnique(typeName, key);
    }

    @PostMapping("/checkTypeCodeUnique")
    public boolean checkTypeCodeUnique(String typeCode, String key) {
        return dictTypeService.checkTypeCodeUnique(typeCode, key);
    }

    @PostMapping("/add")
    @AutoLog(value = "添加字典分类", level = 1, operationType = OperationTypeEnum.INSERT)
    public boolean add(@RequestBody SysDictTypeCreateVo vo) {
        return dictTypeService.add(vo);
    }

    @PutMapping("/edit")
    @AutoLog(value = "编辑字典分类", level = 1, operationType = OperationTypeEnum.UPDATE)
    public boolean edit(@RequestBody SysDictTypeUpdateVo vo) {
        return dictTypeService.edit(vo);
    }

    @DeleteMapping("/remove")
    @AutoLog(value = "删除字典分类", level = 9, operationType = OperationTypeEnum.DELETE)
    public boolean remove(String key) {
        return dictTypeService.remove(key);
    }

    @GetMapping("/get")
    public SysDictTypeModelVo get(String key) {
        return dictTypeService.get(key);
    }

    @GetMapping("/getByCode")
    public SysDictTypeModelVo getByCode(String code) {
        return dictTypeService.getByCode(code);
    }

    @GetMapping("/getList")
    public List<SysDictTypeViewVo> getList() {
        return dictTypeService.getAll();
    }

    @GetMapping("/getTreeNodes")
    public List<TreeNode> getTreeNodes() {
        return dictTypeService.getTreeNodes();
    }
}
